<template lang="html">
  <div class="main-page" id="login-page">
    <nav-bar :title="'登录'" @goBack="onClickLeft"/>
    <div class="main-content has-header-space">
      <div class="login_logo"></div>
      <div class="login_btn">
        <div class="btns tel_login" @click="login('tel')">手机号登录</div>
        <div class="btns wechat_login" @click="login('wechat')">微信账号登录</div>
        <div :class="is_read ? 'reg_pact read' : 'reg_pact'" v-on:click.stop.prevent="readReg">我已阅读并同意
          <router-link :to="{ path: '/pact/gvrp', params: {} }">《美家美货服务协议》</router-link>及
          <router-link :to="{ path: '/pact/privacy', params: {} }">《共享经济合作伙伴协议》</router-link>
          <router-link :to="{ path: '/pact/privacy', params: {} }">《隐私协议》</router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import { mapActions, mapMutations } from 'vuex'
import NavBar from '@/components/global/nav-bar.vue'

export default {
  components: { NavBar },
  data () {
    return {
      login_loading: false,
      is_read: true
    }
  },
  created () {
    let isRead = sessionStorage.getItem('is_read')
    if (isRead !== null) {
      if (isRead === 'false') {
        this.is_read = false
      } else {
        this.is_read = true
      }
    } else {
      this.is_read = true
    }
  },
  methods: {
    // ...mapMutations('userStore', ['setToken', 'setUser']),
    // ...mapActions('userStore', ['getUserInfo']),
    // 登录
    // login (data) {
    //   return new Promise((resolve, reject) => {
    //     this.$Axios({ url: 'login', data, method: 'post' }).then((resp) => { // 请求成功
    //       console.log(resp)
    //       if (resp.code === 200) {
    //         this.$store.commit('userStore/setToken', { token: resp.data.token })
    //       } else {
    //       }
    //       resolve(resp)
    //     }).catch((error) => { // 请求失败
    //       this.$_requestInterceptor('error', error)
    //       reject(error)
    //     })
    //   })
    // },
    // // 处理提交
    // handleSubmit (form) {
    //   this.login_loading = true
    //   this.login(form).then((resp) => {
    //     if (resp.code === 200) {
    //       // 获取用户数据
    //       this.getUserInfo(resp.data.token).then((resp) => {
    //         this.login_loading = false
    //         if (resp.code === 200) {
    //           // this.$router.push({ name: this.$Config.homeName })
    //         } else {
    //         }
    //       }).catch(errors => {
    //         this.login_loading = false
    //         this.$_requestInterceptor('error', errors)
    //       })
    //     } else {
    //       this.login_loading = false
    //     }
    //   }).catch(errors => {
    //     this.login_loading = false
    //   })
    // },
    login (type) {
      if (this.is_read) {
        if (type === 'tel') {
          this.$router.push('/login/tel_login')
        } else if (type === 'wechat') {
          let wechatConfig = {
            appid: 'wx8d56982e6948ed23',
            redirect_uri: encodeURIComponent(''),
            response_type: 'code',
            scope: 'snsapi_userinfo',
            state: '123'
          }
          window.location = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + wechatConfig.appid + '&redirect_uri=' + wechatConfig.redirect_uri + '&response_type=' + wechatConfig.response_type + '&scope=' + wechatConfig.scope + '&state=' + wechatConfig.state + '#wechat_redirect'
        }
      } else {
        this.$toast('请选择我已阅读并同意美家美货服务协议')
      }
    },
    onClickLeft () {
      this.$router.go(-1)
    },
    // 阅读协议
    readReg (e) {
      if (e.target.tagName === 'DIV') {
        sessionStorage.setItem('is_read', !this.is_read)
        this.is_read = !this.is_read
      }
    }
  }
}
</script>

<style lang="css" scoped>
</style>
